﻿using PComponent.utility.sharedprop;
using SharedPropertyLib;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace SharedPropTest2
{
    /// <summary>
    /// This is an example of simple class, 
    /// it's just like a ViewModel for the App,
    /// but can be what ever you want, the main thing 
    /// is that you have to use [SharedProp] for property
    /// You want to "share"
    /// </summary>
    public class AppViewModel:SharedPropHolder,INotifyPropertyChanged
    {
        #region singleton
        static volatile AppViewModel _service=null;
        static object syncRoot = new object();

        AppViewModel() {  }
        public static AppViewModel Service
        {
        
            get{
                if (_service == null) {
                    lock (syncRoot)
                    {   
                        if(_service==null)
                            _service = new AppViewModel();
                    }
                }
                return _service;
            }
        
        }
        
      
        

        #endregion

        #region Public Property

        int _testNumber = 5;

        //add this attribute to made this property available to all
        [SharedProp]    
        public int TestNumber { 
            
            get{ return _testNumber;}
            set {
                if (value != _testNumber)
                {
                    _testNumber = value;
                    if(PropertyChanged!=null)
                        PropertyChanged(this,new PropertyChangedEventArgs("TestNumber"));
                }
                Debug.WriteLine("TestNumber value: " + value);
            
            }
        }


        #endregion

       
        public event PropertyChangedEventHandler PropertyChanged;
    }
}
